package com.chenjt.juc.three_completableFuture;

import java.util.concurrent.CompletableFuture;

/**
 * 注释：
 *
 * @author chenjt
 * @date 2024/7/6 14:19
 */
public class CompletableFutureAPI3Demo {
    public static void main(String[] args) {

//        thenAccept();

        // 输出结果：null
        System.out.println(CompletableFuture.supplyAsync(()-> "resultA").thenRun(()->{}).join());
        // 输出结果：resultA   null
        System.out.println(CompletableFuture.supplyAsync(()-> "resultA").thenAccept(r-> System.out.println(r)).join());
        // 输出结果：resultAresultB
        System.out.println(CompletableFuture.supplyAsync(()-> "resultA").thenApply(r->r+"resultB").join());


    }

    private static void thenAccept() {
        CompletableFuture.supplyAsync(()->{
            return 1;
        }).thenApply(f->{
            return f+2;
        }).thenApply(f->{
            return f+3;
        }).thenAccept(r->{
            System.out.println(r);
        });
    }
}
